/*
 * d=3
 * n=56
 * m=45
 * c=1.23
 * maxlen=12
 * minklen=4
 * maxklen=38
 * minchar=65
 * maxchar=95
 * loop=1
 * numiter=1
 * seed=
 */

static int g[] = {
	-114, 22, 6, 0, -7, 6, 36, -1, -13, 0,
	40, -6, -29, 37, 35, 55, 1, 25, 58, 5,
	31, 0, 47, 7, 0, 0, 74, 30, 38, -31,
	45, 67, -36, 0, 0, 4, 10, 0, 0, -17,
	12, -7, -34, 18, 0, -25, 69, 0, -44, -19,
	22, 0, 25, 0, 8, 0, 
};

static int T0[] = {
	33, 54, 25, 17, 49, 12, 31, 30, 17, 38,
	23, 18, 28, 51, 14, 7, 24, 12, 42, 4,
	32, 35, 51, 50, 15, 12, 4, 12, 0, 35,
	36, 53, 41, 20, 25, 23, 27, 55, 33, 16,
	51, 3, 4, 3, 17, 20, 15, 14, 32, 42,
	40, 24, 30, 21, 12, 9, 38, 36, 12, 4,
	24, 10, 50, 25, 5, 41, 51, 55, 30, 53,
	34, 55, 25, 28, 27, 2, 6, 25, 28, 10,
	25, 5, 49, 53, 30, 46, 19, 41, 55, 49,
	3, 46, 10, 55, 18, 18, 32, 0, 53, 51,
	24, 2, 29, 53, 25, 10, 42, 5, 50, 51,
	11, 7, 11, 39, 12, 26, 41, 51, 26, 43,
	46, 14, 30, 43, 55, 44, 55, 37, 25, 9,
	30, 21, 19, 27, 9, 4, 28, 32, 45, 15,
	46, 3, 14, 21, 4, 53, 53, 33, 22, 27,
	42, 20, 26, 35, 4, 29, 23, 20, 51, 17,
	39, 38, 30, 28, 50, 12, 44, 5, 13, 18,
	51, 18, 50, 40, 35, 5, 14, 15, 53, 55,
	22, 38, 11, 42, 41, 7, 45, 36, 55, 24,
	32, 36, 46, 25, 35, 20, 41, 47, 29, 27,
	29, 10, 45, 48, 8, 31, 52, 29, 21, 28,
	36, 39, 52, 2, 14, 6, 4, 1, 16, 34,
	17, 48, 12, 29, 17, 55, 9, 1, 17, 26,
	8, 19, 26, 38, 33, 24, 32, 54, 50, 13,
	43, 47, 24, 46, 21, 37, 36, 16, 19, 46,
	29, 40, 42, 9, 39, 33, 25, 25, 24, 14,
	26, 32, 13, 3, 6, 49, 48, 17, 19, 3,
	8, 14, 17, 30, 32, 3, 42, 14, 27, 41,
	41, 15, 30, 22, 40, 41, 30, 9, 22, 6,
	48, 12, 18, 13, 16, 9, 42, 17, 39, 41,
	24, 30, 28, 7, 7, 30, 29, 5, 35, 4,
	1, 42, 40, 34, 52, 33, 2, 39, 3, 22,
	27, 35, 21, 30, 27, 40, 7, 0, 0, 54,
	10, 16, 24, 13, 3, 54, 10, 19, 26, 29,
	55, 30, 28, 25, 6, 30, 5, 37, 45, 19,
	45, 13, 30, 34, 1, 36, 3, 35, 28, 26,
	4, 55, 40, 48, 48, 15, 6, 7, 50, 13,
	32, 17, 
};

static int T1[] = {
	46, 33, 4, 14, 27, 50, 4, 13, 29, 46,
	21, 1, 29, 49, 11, 47, 31, 44, 55, 49,
	38, 39, 23, 37, 36, 39, 4, 52, 18, 10,
	0, 40, 22, 21, 0, 29, 4, 17, 5, 2,
	36, 23, 17, 11, 37, 10, 13, 54, 36, 21,
	37, 32, 12, 11, 38, 48, 53, 14, 2, 5,
	3, 26, 51, 22, 43, 55, 18, 19, 1, 40,
	43, 50, 37, 21, 15, 24, 33, 34, 20, 50,
	23, 33, 52, 51, 45, 36, 14, 11, 52, 10,
	8, 44, 32, 1, 30, 7, 32, 8, 49, 51,
	38, 28, 15, 20, 21, 37, 47, 42, 17, 41,
	31, 8, 22, 0, 41, 31, 9, 43, 50, 10,
	47, 11, 27, 44, 18, 14, 54, 20, 16, 13,
	52, 2, 19, 53, 55, 17, 32, 17, 13, 50,
	18, 8, 30, 55, 35, 43, 10, 36, 8, 25,
	5, 51, 52, 36, 4, 47, 53, 17, 14, 26,
	10, 21, 53, 12, 12, 9, 38, 26, 52, 24,
	13, 31, 31, 6, 36, 52, 30, 12, 6, 33,
	51, 41, 36, 24, 35, 39, 0, 54, 0, 44,
	17, 44, 15, 17, 46, 36, 0, 30, 53, 13,
	10, 18, 1, 16, 22, 24, 37, 42, 38, 26,
	38, 15, 12, 32, 39, 20, 27, 14, 35, 37,
	30, 29, 26, 41, 19, 11, 4, 49, 42, 41,
	45, 29, 39, 22, 30, 32, 29, 46, 53, 0,
	2, 25, 4, 1, 17, 40, 9, 14, 52, 42,
	26, 54, 33, 24, 41, 44, 23, 6, 22, 12,
	20, 15, 51, 32, 55, 6, 33, 44, 49, 5,
	54, 51, 31, 31, 32, 46, 43, 25, 15, 4,
	34, 47, 25, 25, 11, 28, 14, 21, 18, 16,
	28, 47, 4, 41, 44, 40, 47, 48, 16, 39,
	50, 0, 48, 53, 20, 11, 21, 3, 44, 24,
	34, 31, 15, 17, 14, 32, 24, 32, 11, 52,
	47, 1, 4, 44, 11, 23, 22, 46, 47, 10,
	14, 15, 53, 51, 22, 47, 8, 17, 14, 27,
	9, 47, 29, 40, 14, 12, 50, 11, 27, 24,
	39, 51, 20, 29, 0, 6, 36, 42, 51, 0,
	11, 15, 50, 42, 53, 43, 48, 50, 10, 19,
	30, 14, 
};

static int T2[] = {
	8, 51, 18, 2, 8, 28, 26, 40, 13, 53,
	8, 42, 33, 21, 39, 6, 15, 1, 36, 29,
	11, 7, 50, 21, 50, 1, 25, 34, 3, 2,
	18, 39, 24, 36, 6, 49, 47, 41, 26, 43,
	34, 20, 7, 51, 34, 26, 14, 2, 47, 0,
	39, 34, 39, 23, 18, 34, 33, 55, 4, 49,
	29, 52, 40, 14, 35, 49, 26, 40, 10, 9,
	20, 30, 45, 50, 41, 16, 11, 27, 15, 10,
	42, 38, 45, 35, 53, 42, 23, 47, 32, 44,
	2, 18, 18, 32, 48, 8, 32, 0, 18, 53,
	36, 39, 38, 0, 35, 28, 26, 16, 22, 29,
	41, 6, 25, 42, 31, 11, 53, 44, 46, 14,
	8, 28, 46, 51, 49, 53, 1, 17, 40, 55,
	29, 13, 11, 19, 51, 3, 38, 8, 15, 3,
	16, 22, 28, 18, 46, 22, 52, 33, 52, 47,
	43, 10, 10, 21, 4, 0, 40, 16, 40, 9,
	16, 8, 22, 2, 3, 36, 8, 28, 18, 44,
	6, 53, 3, 23, 5, 19, 41, 16, 25, 45,
	6, 6, 42, 28, 22, 12, 6, 25, 4, 43,
	4, 46, 7, 29, 20, 36, 53, 50, 31, 5,
	26, 37, 42, 50, 37, 46, 11, 48, 51, 39,
	45, 18, 18, 26, 18, 4, 5, 55, 41, 0,
	31, 24, 44, 7, 54, 49, 12, 13, 6, 38,
	15, 24, 49, 21, 22, 24, 7, 43, 34, 7,
	55, 35, 38, 45, 33, 46, 9, 4, 31, 9,
	46, 38, 52, 11, 4, 14, 9, 35, 47, 0,
	6, 23, 50, 6, 34, 10, 22, 22, 31, 24,
	54, 43, 7, 16, 18, 24, 21, 39, 8, 2,
	19, 17, 30, 30, 11, 33, 52, 24, 52, 30,
	40, 19, 1, 31, 36, 16, 21, 16, 8, 9,
	20, 11, 20, 25, 37, 44, 46, 52, 7, 11,
	49, 2, 53, 33, 45, 41, 46, 40, 23, 23,
	14, 6, 39, 15, 51, 36, 7, 4, 3, 15,
	17, 22, 10, 11, 34, 13, 20, 53, 54, 13,
	4, 17, 31, 35, 36, 48, 43, 55, 9, 19,
	11, 38, 48, 16, 31, 38, 39, 36, 11, 3,
	28, 53, 5, 0, 8, 11, 21, 31, 51, 53,
	47, 9, 
};

#define uchar unsigned char

int
h3m_object_hash(const uchar *key)
{
	int i;
	unsigned f0, f1, f2;
	const uchar *kp = key;

	for (i=-65, f0=f1=f2=0; *kp; ++kp) {
		if (*kp < 65 || *kp > 95)
			return -1;
		if (kp-key > 37)
			return -1;
		f0 += T0[i + *kp];
		f1 += T1[i + *kp];
		f2 += T2[i + *kp];
		i += 31;
		if (i >= 307)
			i = -65;
	}

	if (kp-key < 4)
		return -1;

	f0 %= 56;
	f1 %= 56;
	f2 %= 56;

	if (f1 == f0 && ++f1 >= 56)
		f1 = 0;
	if (f2 == f0 && ++f2 >= 56)
		f2 = 0;
	if (f1 == f2) {
		if (++f2 >= 56)
			f2 = 0;
		if (f2 == f0 && ++f2 >= 56)
			f2 = 0;
	}

	return g[f0] + g[f1] + g[f2];
}